﻿
@{
    ViewBag.Title = "系统用户编辑 - " + ViewBag.DomainTitle;
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="layui-fluid">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>编辑</legend>
    </fieldset>
</div>

<form class="layui-form query-form" id="dataForm">
    <input type="text" id="ID" name="ID" value="@ViewBag.ID" class="layui-hide" />
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">账号</label>
            <div class="layui-input-inline">
                <input type="text" name="Account" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
                <input type="text" name="Password" class="layui-input" placeholder="不填写默认为配置密码">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-inline">
                <input type="text" name="Name" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-inline">
                <input type="text" name="Remark" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否有效</label>
        <div class="layui-input-block">
            <input type="checkbox" name="IsValid" lay-skin="switch" lay-text="T|F" checked>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <span class="layui-btn layui-btn-sm" onclick="javascript: { submitData(); }">保存</span>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm" id="btnReset">重置</button>
            <a class="layui-btn layui-btn-warm layui-btn-sm" href="/SysUser/Index">返回</a>
        </div>
    </div>
</form>

@Html.Partial("~/Views/Shared/_Script.cshtml")

<script>
    var form = layui.form;
    $(function () {
        var id = $('#ID').val();
        if (id) {
            bindData(id);
        }
    });
    // 绑定数据
    function bindData(id) {
        $.post('/SysUser/AjaxEntity', { id: id }, function (result) {
            result.data.Password = '';
            $('#dataForm').setForm(result.data);
            form.render();
        });
    };
    // 提交数据
    function submitData() {
        var data = $('#dataForm').getForm();
        if (data.IsValid)
            data.IsValid = true;
        else
            data.IsValid = false;
        $.post('/SysUser/AjaxEdit', data, function (result) {
            layer.msg(result.msg);
            $('#btnReset').click();
        });
    };
</script>
